package com.jieyun.rbac.controller;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jieyun.core.utils.ServerResponse;
import com.jieyun.core.utils.SessionUtils;
import com.jieyun.rbac.service.IndexService;
import com.jieyun.rbac.service.SysAclModuleService;

/**
 * 首页的请求处理
 * @author trek
 */
@Controller
public class SysIndexController {
	
	@Resource
	private IndexService indexService;
	
	@Resource
	private SysAclModuleService sysAclModuleService;
	
	/**
	 * 返回到登录页面
	 * @return
	 */
	@RequestMapping("/")
	public String  index() {
		return "login";
	}
	
	/**
	 * 进入系统
	 * @return
	 */
	@GetMapping("/main")
	public String main() {
		return "main";
	}
	
	/**
	 * 用户登录
	 * @param username
	 * @param password
	 * @return
	 */
	@RequestMapping("/sys/login")
	@ResponseBody
	public ServerResponse login(String username,String password) {
		return this.indexService.login(username,password);
	}
	
	
	/**
	 * 获取用户信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping("userInfo")
	public ServerResponse userInfo() {
		return ServerResponse.ok(SessionUtils.getUser());
	}
	
	/**
	 * 退出系统登录
	 * @return
	 */
	@RequestMapping("logout")
	public String logout() {
		SecurityUtils.getSubject().logout();
		return "redirect:/";
	}
	
	/**
	 * 返回首页
	 * @return
	 */
	@RequestMapping("index")
	public String indexPage() {
		return "index";
	}
}
